package cn.uniquesoft.api;

import cn.uniquesoft.service.IVideosService;
import cn.uniquesoft.vo.ArticleVO;
import cn.uniquesoft.vo.VideosVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/api/video")
public class ApiVideoController {
    @Value("${resource.pagesize}")
    private int pagesize;
    @Autowired
    private IVideosService videosService;

    @RequestMapping(value = "/getCompanyVideo")
    @ResponseBody
    public String getCompanyVideo(int iid, String option ) {
        List<VideosVO> itemList = new ArrayList<>();
        VideosVO v = new VideosVO();
        v.setIid(iid);
        v.setPageSize(this.pagesize);
        if(option.equals("down")){
            if(iid==0){
                itemList =  this.videosService.getItemsFirst(this.pagesize);
            }else{
                itemList =  this.videosService.getItemsDown(v);
            }

        }else{
            itemList =  this.videosService.getItemsUp(v);
        }
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(VideosVO.class, "iid", "ctitle", "curl","dcreator");
        String str = JSON.toJSONString(itemList, filter);
        return str;
    }

}
